package com.example.visitedsys.Controller;

import com.example.visitedsys.Shrio.Bean.Notice;
import com.example.visitedsys.Shrio.Bean.ResponseBean;
import com.example.visitedsys.redis.RedisUtil;
import com.example.visitedsys.utils.chong;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.visitedsys.utils.chong;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @version 1.0
 * @ClassName IndexController
 * @Description TODO
 * @Author SongPeng
 * @Date 2021/12/12 14:33
 **/
@RestController
@RequestMapping("/index")
public class IndexController {
    String redis_key="Notice_key";
    private static final Logger logger = LogManager.getLogger(IndexController.class);
    @Autowired
    Notice notice;
    @Autowired
    chong chong;
    @Autowired
    RedisUtil redisUtil;

    @GetMapping("/Notice")
    public ResponseBean Notice(){
        logger.info("获取公告");
        if(redisUtil.hasKey(redis_key)){
            return ResponseBean.success(redisUtil.get(redis_key));
        }
        else{
            //        List<String> list;
            List<Object> list = chong.chong();
            redisUtil.set(redis_key,list,86400);
            return ResponseBean.success(list);
        }
    }
}
